package com.os.lambda.chapter1;

import java.util.Arrays;
import java.util.List;
import java.util.Optional;

public class LambdaDemo {

    public static void main(String[] args) {
        Runnable runnable = new Runnable() {
            @Override
            public void run() {
                System.out.println("匿名内部类，求求你：用Lambda语法创建多线程吧!");
            }
        };

        //匿名内部类的调用方式
        new Thread(runnable).start();

        //lambda表达式调用方式
        new Thread(()-> System.out.println("使用lambda表达式就对了!")).start();


        List<Person> guiltyPersons = Arrays.asList(
            new Person("matt", "linus", 20),
            new Person("ma jack", "maYun", 20),
            new Person("god", "linus", 20)
        );
        guiltyPersons.stream()
                .filter(p->p.getFirstName().startsWith("m"))
                .forEach(System.out::println);

        Person person = null;
        Optional<Person> personOptional = Optional.ofNullable(person);
        //personOptional.isPresent(System.out::println);

        MyLambdaInterface myLambdaInterface = (s) -> {
            System.out.println(s);
        };

        enact(s -> System.out.println(s), "Hello World!");


    }

    public static void enact(MyLambdaInterface myLambdaInterface, String s){
        myLambdaInterface.doSomething(s);
    }
}
